package tree;

import offer.TreeNode;

public class leetCode98_isValidBST {
    long pre = Long.MIN_VALUE;
    public boolean isValidBST(TreeNode root) {
        return build(root);

    }
    // 中序遍历应该是一个递增序列
    public boolean build(TreeNode root){
        if(root == null) return true;

        if(!build(root.left)){
            return false;
        }
        if(root.val < pre){
            return false;
        }else{
            pre = root.val;
        }
        if(!build(root.right)){
            return false;
        }
        return true;
    }



}
